package src.schoolWork;

import java.io.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: tao
 * Date: 2023-11-20
 * Time: 14:43
 */
public class Test1 {
    public static void main(String[] args) {
        try {
            FileReader fileReader1 = new FileReader("D:\\桌面\\java\\学校作业\\First.txt");
            FileReader fileReader2 = new FileReader("D:\\桌面\\java\\学校作业\\Second.txt");
            BufferedReader bufferedReader1 = new BufferedReader(fileReader1);
            BufferedReader bufferedReader2 = new BufferedReader(fileReader2);
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("D:\\桌面\\java\\学校作业\\Third.txt"));

            String s1, s2;
            s1 = bufferedReader1.readLine();
            while (s1 != null) {
                bufferedWriter.write(s1);
                s1 = bufferedReader1.readLine();
                bufferedWriter.newLine();
            }
            s2 = bufferedReader2.readLine();
            while (s2 != null) {
                bufferedWriter.write(s2);
                s2 = bufferedReader2.readLine();
                bufferedWriter.newLine();
            }
            bufferedReader1.close();
            bufferedReader2.close();
            bufferedWriter.close();
            System.out.println("文件合并成功");
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
